package android.medicalcloud.com.yiapp.yilian.application;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.medicalcloud.com.yiapp.yilian.configer.xml.HttpManager;
import android.os.Bundle;
import android.os.Environment;

import com.tencent.TIMManager;
import com.umeng.analytics.MobclickAgent;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by wanggenlin on 17-5-18.
 */
public class YilianAppcation extends Application  implements Application.ActivityLifecycleCallbacks {
    public static YilianAppcation instance;
    List<Activity> list;
    public  Activity currentActivity;
    private static Context context;
    public static YilianAppcation getInstance() {
        return instance;
    }
    public static final String LOGPATH = Environment.getExternalStorageDirectory().getPath() + File.separator + "yilian";
    public static String fileDir = "yilian";

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        context = getApplicationContext();
        HttpManager.getInstance().init();
        registerActivityLifecycleCallbacks(this);


        MobclickAgent.setDebugMode(true);
        MobclickAgent.openActivityDurationTrack(false);
        MobclickAgent.setScenarioType(this, MobclickAgent.EScenarioType.E_UM_NORMAL);

        TIMManager.getInstance().init(this);
        list = new ArrayList<>();



    }
    public Context getContext() {
        return context;
    }
    @Override
    public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
        list.add(activity);
    }

    @Override
    public void onActivityStarted(Activity activity) {

    }

    @Override
    public void onActivityResumed(Activity activity) {
        currentActivity = activity;
    }

    @Override
    public void onActivityPaused(Activity activity) {

    }

    @Override
    public void onActivityStopped(Activity activity) {

    }

    @Override
    public void onActivitySaveInstanceState(Activity activity, Bundle outState) {

    }

    @Override
    public void onActivityDestroyed(Activity activity) {

    }


    public void clear(){
        for (Activity ac:list){
            if (ac!=null&&!ac.isFinishing()){
                ac.finish();
            }
        }
    }
}
